package com.gmail.shazi199.satoriex.stage;

import java.util.ArrayList;
import java.util.List;

import org.lwjgl.input.Keyboard;

import com.gmail.shazi199.satoriex.App;
import com.gmail.shazi199.satoriex.entity.Controllable;
import com.gmail.shazi199.satoriex.entity.impl.Enemy;
import com.gmail.shazi199.satoriex.entity.impl.Player;
import com.gmail.shazi199.satoriex.entity.impl.Satori;
import com.gmail.shazi199.satoriex.stage.image.StageFront;
import com.gmail.shazi199.satoriex.utils.Drawer;

public class SatoriStage implements BaseStage, Controllable {

    private Player player;
    private StageFront stageFront;
    private List<Enemy> enemyList;

    @Override
    public void update() {
        while (Keyboard.next()) {
            this.keyboardUpdate();
            player.keyboardUpdate();
        }
        player.update();
        for (int i = 0; i < enemyList.size(); i++) {
            enemyList.get(i).update();
        }
    }

    @Override
    public void draw() {
        Drawer.clear();
        for (int i = 0; i < enemyList.size(); i++) {
            enemyList.get(i).draw();
        }
        player.draw();
        stageFront.draw();
    }

    @Override
    public void keyboardUpdate() {
        if (!Keyboard.getEventKeyState()) {
            switch (Keyboard.getEventKey()) {
            case Keyboard.KEY_ESCAPE:
                App.getApp().setStage(new TitleStage());
                break;
            default:
                break;
            }
        }
    }

    private void init() {
        stageFront = new StageFront();
        enemyList.add(new Satori());
    }

    public SatoriStage(Player player) {
        this.player = player;
        enemyList = new ArrayList<Enemy>();
        init();
    }

    @Override
    public Player getPlayer() {
        return this.player;
    }
}
